/**
 * Created with JetBrains WebStorm.
 * User: thaidoanhong
 * Date: 3/25/13
 * Time: 10:25 PM
 * To change this template use File | Settings | File Templates.
 */
/**
 * Created with JetBrains WebStorm.
 * User: thaidoanhong
 * Date: 3/25/13
 * Time: 10:25 PM
 * To change this template use File | Settings | File Templates.
 */
var MyAttributeList = Class.create({
    initialize: function(){
        this.attributeList = new Array();
    },
    add: function(o){
        this.attributeList.push(o);
    },
    getValueFromKey: function(caller, key){
        for(var i=0;i<this.attributeList.length;i++){
            if(this.attributeList[i].key == key){
                if(this.attributeList[i].type == "css"){
                    return $(caller.id).getStyle(this.attributeList[i].key);
                }
                return this.attributeList[i].value;
            }
        }
        return null;
    },
    getValueFromName : function(caller, name){
        for(var i=0;i<this.attributeList.length;i++){
            if(this.attributeList[i].name == name){
                if(this.attributeList[i].type == "css"){
                    return $(caller.id).getStyle(this.attributeList[i].key);
                }
                return this.attributeList[i].value;
            }
        }
        return null;
    },
    setValueByKey: function(caller, key, value){
        for(var i=0;i<this.attributeList.length;i++){
            if(this.attributeList[i].key == key){
                this.attributeList[i].value = value;

                if(this.attributeList[i].type == "css"){
                    var sty = {};
                    sty[this.attributeList[i].key] = this.attributeList[i].value;
                    $(caller.id).setStyle(sty);
                }

                return true;
            }
        }
        return false;
    },
    setValueByName: function(caller, name, value){
        for(var i=0;i<this.attributeList.length;i++){
            if(this.attributeList[i].name == name){
                this.attributeList[i].value = value;

                if(this.attributeList[i].type == "css"){
                    var sty = {};
                    sty[this.attributeList[i].key] = this.attributeList[i].value;
                    $(caller.id).setStyle(sty);
                }

                return true;
            }
        }
        return false;
    },
    getSize: function(){
        return this.attributeList.length;
    }
})